﻿
var isfind = '';
var selectdate = '';
var orderid = '';

$(function () {
    isfind = getQuery('isfind');
    orderid = getQuery('orderid');
    selectdate = getQuery('selectdate');
    if (isfind == '') {
        GetOrder();
    }

    $('#yaodiandtdw').click(function () {
        var yaodianming = $('#ydmc').val();
        var yaodiandizhi = $('#ydaddr').val();
        //yaodianming += ' ' + yaodiandizhi;
        window.location.href = "http://" + A_Url + '/Main/weixin/guke_order_dingwei.html?yaodianming=' + yaodianming;
    });
});

//获取已经预定信息
function GetOrder() {

    $.showLoading();
    var tm = setTimeout(function () {
        $.hideLoading();
        $.alert("系统繁忙，请稍后再试！", "超时", function () { });
    }, 20000);

    $.ajax({
        type: "GET",
        url: "http://" + A_Url + "/api/yudingfind",
        //数据，json字符串
        data: { info: 'getorderDetail', XiaoShouDingji: orderid,selectdate: selectdate},
        success: function (result) {
            $.hideLoading();
            clearTimeout(tm);
            if (result == undefined || result == null || result.YaoDianID == null || result.YuDingShu == null) {
                $("#qr").empty();
                $.alert("没有预定记录！", "未预定", function () {                
                    return;
                });
            } else {
                $('#birthday').val(formartDateInt(result.YuDingRiQi));
                $('#ydmc').val(result.YaoDianMing);
                $('#ydaddr').val(result.YaoDianDiZhi);
                $('#js_input_xm').val(result.XingMing);
                //$('#js_input_sfz').val(result.ShenFenZheng);
                $('#js_input_sfz').val(result.ShenFenZheng.substr(0, 6) +'********'+result.ShenFenZheng.substr(14, 4));
                $('#js_input_sl').val(result.YuDingShu);
                $('#js_input_dhhm').val(result.DianHuan);

                qr("http:////" + B_Url + '/Main/weixin/yuding_Customer_order.html?id=' + orderid + '&selectdate=' + result.YuDingRiQi);
            }
        },
        error: function (e) { }
    });

   
}

//
function qr(url) {
    const canvas = qrcanvas.qrcanvas({ data: url, size: 200, foreground: 'red', background: 'white' });
    $("#qr").empty().html(canvas2image(canvas));
}

function canvas2image(canvas) {
    var image = new Image();
    image.src = canvas.toDataURL("image/png");
    return image;
}

